install.packages("tidyverse")
install.packages("haven")
install.packages("reshape")
install.packages("ggplot2")

library(tidyverse)
library(haven)
library(reshape)
library(ggplot2)


#Set Work Directory.
setwd("C:/Users/RCASES/OneDrive - Centro de Estudios Públicos/CEP/Bases de datos/Latinobarómetro")

#Read data frame.
approval_data <- read_dta("approval_data.dta")

#--------------------------------------------
#-----------------------Graphics-------------
#--------------------------------------------


#Average approval over time 

approval_data %>% 
  ggplot(aes(x=year,
             y=approval,
             group=president,
             color=president))+
  geom_line()+
  geom_point()+
  xlab("Year")+ylab("Average approval (%)")+
  theme_bw()+
  guides(color=guide_legend(title="President"))+ylim(0,1)

#Prospective and retrospective optimistic over time

approval_data %>% 
  ggplot(aes(x=year, color=president))+
geom_line(aes(y=socio_current_better),cex=1)+
      geom_point(aes(y=socio_current_better),shape=15, size=2)+
geom_line(aes(y=ego_current_better),cex=1)+
      geom_point(aes(y=ego_current_better),shape=17, size=2)+
  xlab("Year")+ylab("%")+
  guides(color=guide_legend(title="President"))+
  theme_bw()


